package cn.cyb.server.mapper;

import cn.cyb.server.domain.entity.SysRole;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author yuebo
 * @date 2025/3/4
 */
@Mapper
public interface SysRoleMapper {

    /**
     * 根据用户ID查询角色
     *
     * @param userId
     * @return
     */
    @Select("select r.role_id, r.role_name, r.role_key, r.create_time from sys_role r " +
            "left join sys_user_role ur on ur.role_id = r.role_id " +
            "left join sys_user u on u.user_id = ur.user_id " +
            "where ur.user_id = #{userId}")
    @Results(value = {
            @Result(property = "roleId", column = "role_id"),
            @Result(property = "roleName", column = "role_name"),
            @Result(property = "roleKey", column = "role_key"),
            @Result(property = "createTime", column = "create_time")
    })
    List<SysRole> selectRolePermissionByUserId(Long userId);
}
